#ifndef MDSPI_H
#define MDSPI_H
#include <memory>
#include <vector>
#include <unordered_map>
#include <set>
#include "ThostFtdcMdApi.h"
#include "ThostFtdcTraderApi.h"
#include "Struct.h"

class MdSpi : public CThostFtdcMdSpi
{
public:
	MdSpi();
	virtual void OnFrontConnected();
	virtual void OnRspError(CThostFtdcRspInfoField *Rtn, int nRequestID, bool bIsLast);
	virtual void OnRspUserLogin(CThostFtdcRspUserLoginField *Rtn, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    virtual void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *Rtn);
	virtual void OnFrontDisconnected(int nReason);
	void insert(std::string t, Snapshot* m){snapshot_[t] = m;};
	int get_status(){return status;};
private:
	int status;
	std::unordered_map<std::string, Snapshot*> snapshot_;
};

class TdSpi: public CThostFtdcTraderSpi
{
public:
    TdSpi();    
    void OnFrontConnected();
    void OnRspUserLogin(CThostFtdcRspUserLoginField *Rtn,CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	void OnRspAuthenticate(CThostFtdcRspAuthenticateField *Rtn,CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *Rtn, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	void OnRtnInstrumentStatus(CThostFtdcInstrumentStatusField *Rtn);
	void OnRspQryInstrument(CThostFtdcInstrumentField *Rtn, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnRspError(CThostFtdcRspInfoField *Rtn, int nRequestID, bool bIsLast);
    void OnFrontDisconnected(int nReason);
    void OnHeartBeatWarning(int nTimeLapse);
	std::vector<std::string> get_list(){return list_;};
	void add_universe(const std::string& id){universe_.insert(id);};
	bool is_closed(){return closed_;};
private:
	std::vector<std::string> list_;
	std::set<std::string> universe_;
	bool closed_ = false;
};


#endif
